﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fireball.Extensions
{
    public static class NumbersExtensions
    {
        // 1 Pixel is 9525 Emus

        /// <summary>
        /// Indica il valore di emus corrispondente
        /// ad un pixel
        /// </summary>
        private const decimal EmusAsPixel = 9525;

        /// <summary>
        /// Convert Pixels to Emus
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static decimal PixelToEmus(this decimal n)
        {
            return n * EmusAsPixel;
        }

        /// <summary>
        /// Convert Enums to Pixel
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static decimal EmusToPixel(this decimal n)
        {
            return n / EmusAsPixel;
        }

        /// <summary>
        /// Convert Pixels To Emus
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static int PixelToEmus(this int n)
        {
            return n * (int)EmusAsPixel;
        }

        /// <summary>
        /// Convert Pixels To Emus
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static double PixelToEmus(this double n)
        {
            return n * (double)EmusAsPixel;
        }

        /// <summary>
        /// Convert Enums to Pixel
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static int EmusToPixel(this int n)
        {
            return n / (int)EmusAsPixel;
        }

        /// <summary>
        /// Convert the number to a 8 char hex
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static string ToHex8(this int n)
        {
            return string.Format("{0:X8}", n);
        }

        /// <summary>
        /// Convert the number to a 8 char hex
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static string ToHex8(this long n)
        {
            return string.Format("{0:X8}", n);
        }
    }
}
